package com.qianqu.yuepai.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

import com.alibaba.android.arouter.launcher.ARouter;
import com.qianqu.lib_base.utils.FragmentUtils;
import com.qianqu.yuepai.R;
import com.qianqu.yuepai.adapter.MainAdapter;
import java.util.ArrayList;

/**
 * ${description}
 *
 * @author weiqiliu
 * @version 1.0 2018/6/25
 */
public class MainActivity extends AppCompatActivity {
    private ViewPager viewPager;
    private Button button;
    private MainAdapter mainAdapter;
    private ArrayList<Fragment> fragmentList = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
        setViewPagerAdapter();
    }

    private void initView() {
        button = (Button) findViewById(R.id.button);
        viewPager = (ViewPager) findViewById(R.id.viewPager);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ARouter.getInstance()
                        .build("/test/testARouterActivty")
                        .navigation();
            }
        });
    }

    private void initData() {
        fragmentList.clear();
        fragmentList.add(FragmentUtils.getHomeFragment());
        fragmentList.add(FragmentUtils.getFindingFragment());
        fragmentList.add(FragmentUtils.getMessageFragment());
    }

    private void setViewPagerAdapter() {
        mainAdapter = new MainAdapter(getSupportFragmentManager(), fragmentList);
        viewPager.setAdapter(mainAdapter);
    }

}
